module.exports = (options) => {
  
    return async function getUser(ctx, next) {

      if (ctx.path == '/code') return await next()

      if (ctx.path == '/login') return await next()

      let token = ctx.request.header.authorization

      if (!token){

          ctx.status = 200;

          ctx.body = {

            message: 'miss token',

            status: 401

          };

      }

      token = token.substring(7)

      try {

          const de = ctx.app.jwt.verify(token, options.secret)

          await next()

      } catch (error) {

          ctx.status = 200;

          ctx.body = {

            message: error.message,

            status: 401

          };
        
      }
    };
}